package com.itqf.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/** spring+web整合后
 * spring容器之外的对象 获取Spring容器构建的对象的方式
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/11/27
 * @Time: 下午6:03
 */
@Component
public class SpringUtils implements ApplicationContextAware {

    static ApplicationContext applicationContext=null;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringUtils.applicationContext = applicationContext;//赋值
    }

    public  static  Object  getBean(String name)
    {
        return applicationContext.getBean(name);
    }

}
